namespace Maple.Branch.Identity.DataSeed
{
    using System.Threading.Tasks;
    using Configurations;
    using Volo.Abp.Data;
    using Volo.Abp.DependencyInjection;

    public class IdentityDataSeedContributor : IDataSeedContributor, ITransientDependency
    {
        public IdentityDataSeedContributor(IIdentityDataSeeder identityDataSeeder,
            IRootConfiguration rootConfiguration)
        {
            IdentityDataSeeder = identityDataSeeder;
            RootConfiguration = rootConfiguration;
        }

        protected IIdentityDataSeeder IdentityDataSeeder { get; }

        protected IRootConfiguration RootConfiguration { get; }

        public virtual Task SeedAsync(DataSeedContext context)
        {
            return IdentityDataSeeder.CreateAdminAsync(
                context["AdminEmail"] as string ?? RootConfiguration.Admin.Email,
                context["AdminPassword"] as string ?? RootConfiguration.Admin.Password,
                context.TenantId
            );
        }
    }
}
